﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SZDomain.Aaron.Demo.Context
{
    public class ContextProvider
    {
        #region  属性定义
        public string username
        {
            get;
            set;
        }
        public static readonly string forumKey = "{2EEB5D44-75AE-4e7c-9D5E-4A1ABCF4F049}";
        private HttpContext _context;
        #endregion

        #region 构造器
        private ContextProvider(HttpContext hc)
        { 
            this._context=hc;
        }
        #endregion
        public static ContextProvider Current
        {
            get {
                HttpContext hc = HttpContext.Current;
                if (hc != null)
                {
                    if (hc.Items.Contains(forumKey))
                    {
                        return hc.Items[forumKey] as ContextProvider;
                    }
                    else
                    {
                        ContextProvider cp=new ContextProvider(hc);
                        return cp;
                    }
                }
                else { 
                    throw new Exception("Erro! no httpcontext!");
                }
            }
        }
    }
}
